package com.xzc.algorithm.data_structure_ke.LinkedList;

import scala.actors.LinkedNode;

public class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }

    public void parse(int[] arr) throws Exception {
        if (arr == null || arr.length == 0)
            throw new Exception("数组为空");
        ListNode tmp = this;
        tmp.val = arr[0];
        for (int i = 1; i < arr.length; i++) {
            tmp.next = new ListNode(arr[i]);
            tmp = tmp.next;
        }
    }

    @Override
    public String toString() {
        StringBuilder strBd = new StringBuilder();
        ListNode tmp = this;
        strBd.append(tmp.val);
        while (tmp.next != null) {
            strBd.append("->").append(tmp.next.val);
            tmp = tmp.next;
        }
        return strBd.toString();
    }
}
